package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.AppRoleCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.AppRoleQueryDTO;
import com.winshare.saleAssistant.domain.dto.req.AppRoleUpdateDTO;
import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.service.AppRoleService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/app/role")
@CrossOrigin
@Api(value = "应用角色", description = "应用角色")
public class AppRoleController {

    private final AppRoleService appRoleService;

    public AppRoleController(AppRoleService appRoleService) {
        this.appRoleService = appRoleService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增应用角色",notes = "新增应用角色")
    public LogicResponse save(@RequestBody @Validated AppRoleCreateDTO appRoleCreateDTO) {
        appRoleService.saveAppRole(appRoleCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改应用角色",notes = "修改应用角色")
    public LogicResponse update(@RequestBody @Validated AppRoleUpdateDTO appRoleUpdateDTO) {
        appRoleService.updateAppRole(appRoleUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取应用角色列表",notes = "获取应用角色列表")
    public LogicResponse getAppRoleList(@RequestBody @Validated AppRoleQueryDTO appRoleQueryDTO) {
        return LogicResponse.success(appRoleService.getAppRoleList(appRoleQueryDTO));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除应用角色接口",notes = "删除应用角色接口")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        appRoleService.deleteAppRole(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个应用角色详情",notes = "获取单个应用角色详情")
    public LogicResponse getAppRoleDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(appRoleService.getAppRoleDetail(baseIdDTO));
    }

}
